package com.etc.controller;

import com.etc.entity.FxAdmin;
import com.etc.entity.FxMusician;
import com.etc.service.FxMusicianService;
import com.etc.util.ResponseData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.core.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(value = "")
@CrossOrigin("*")
@Api(value = "")
public class FxMusicianController {
    @Autowired
    FxMusicianService service;

    Logger logger = (Logger) LogManager.getLogger(getClass());

    /**
     * 登入操作
     * @param name
     * @param password
     * @return FxMusician
     */
    @ApiOperation(value = "", notes = "管理员登入",response = FxAdmin.class,code = 200)
    @GetMapping(value = "Musician_login/")
    public FxMusician Select_MusicianLogin(@RequestParam(value = "name", defaultValue = "") String name, @RequestParam(value = "password", defaultValue = "") String password){
        FxMusician fxMusician = service.select_MusicianLogin(name, password);
        logger.info("Select_MusicianLogin"+ fxMusician);
        return fxMusician;
    }

    @ApiOperation(value = "", notes = "查询所有歌手",response = FxMusician.class,code = 200)
    @GetMapping(value = "Musician_All/")
    public ResponseData Select_All(){
        List<FxMusician> list = service.selectMusicianAll();
        ResponseData responseData = new ResponseData();
        responseData.setData(list);
        return responseData;
    }

    @ApiOperation(value = "", notes = "分页模糊查询歌手",response = FxMusician.class,code = 200)
    @GetMapping(value = "Musician_ByPage/")
    public List<FxMusician> Select_ByPage(@RequestParam(value = "pageNo", defaultValue = "1",required = false) int pageNo, @RequestParam(value = "pageSize",defaultValue = "2",required = false) int pageSize,
                                          @RequestParam(value = "keywords", defaultValue = "",required = false) String keywords, @RequestParam(value = "genres", defaultValue = "",required = false) String genres, @RequestParam(value = "type", defaultValue = "",required = false) String type){
        List<FxMusician> list = service.selectMusicianByPage(pageNo, pageSize, keywords, genres, type);
        logger.info("Select_ByPage"+list);
        return list;
    }
}
